Skip to content

feat: add .js extensions for Node.js ESM compatibility#9

Merged
cristinecula merged 1 commit intomasterfrom
feature/neo-935-fix-esm-resolution-add-js-extensions
Feb 7, 2026
Merged

feat: add .js extensions for Node.js ESM compatibility#9
cristinecula merged 1 commit intomasterfrom
feature/neo-935-fix-esm-resolution-add-js-extensions

Conversation

@cristinecula
Copy link
Contributor

Summary

  • Add explicit .js extensions to all local imports in TypeScript source files
  • Ensures the compiled output works correctly in Node.js ESM environments (e.g., Vitest with moduleResolution: 'bundler')

Problem

When using @neovici/testing in a Vitest unit test environment (jsdom), the following error occurs:

Error: Failed to resolve import "./result" from "node_modules/@neovici/testing/dist/render-hook.js"

This happens because Node.js ESM requires explicit file extensions in imports, but the compiled TypeScript output was missing them.

Solution

Following the TypeScript recommendation for libraries, we add .js extensions to all local imports in the source files. TypeScript preserves these extensions in the output, making the package compatible with both bundlers AND Node.js ESM.

Changes

  • src/index.ts - Added .js extensions + documentation comment
  • src/render-hook.ts - Added .js extensions to imports
  • src/renderer.ts - Added .js extension to import
  • src/result.ts - Added .js extension to import

Testing

  • npm run lint passes
  • npm run build produces output with .js extensions
  • npm test passes (14 tests)

Fixes NEO-935

Add explicit .js extensions to all local imports to ensure the compiled
output works correctly in Node.js ESM environments (e.g., Vitest with
moduleResolution: 'bundler').

This follows the TypeScript recommendation for libraries:
https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-writing-a-library

Fixes NEO-935
@cristinecula cristinecula self-assigned this Feb 7, 2026
@cristinecula cristinecula marked this pull request as ready for review February 7, 2026 10:21
@cristinecula cristinecula changed the title fix: add .js extensions for Node.js ESM compatibility r4: add .js extensions for Node.js ESM compatibility Feb 7, 2026
@cristinecula cristinecula changed the title r4: add .js extensions for Node.js ESM compatibility feat: add .js extensions for Node.js ESM compatibility Feb 7, 2026
@cristinecula cristinecula merged commit 6b19761 into master Feb 7, 2026
2 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 7, 2026
## 2.3.0 (2026-02-07)

* feat: add .js extensions to imports for Node.js ESM compatibility (#9) ([6b19761](6b19761)), closes [#9](#9)
@github-actions
Copy link

github-actions bot commented Feb 7, 2026

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants